<!--
  #%L
  thinkbig-ui-operations-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->
<card-layout header-css="filter-header">
  <header-section tba-card-filter-header transclude-to="head" flex layout card-title="vm.cardTitle" page-name="{{vm.pageName}}" view-type="vm.viewType" sort-options="vm.sortOptions"
                  on-menu-open="vm.onOptionsMenuOpen" on-selected-option="vm.selectedTableOption" additional-options="vm.additionalMenuOptions"
                  on-selected-additional-option="vm.selectedAdditionalMenuOption" filter-model="vm.filter" filter-model-options="{debounce:1000}"
                  on-show-filter-help="vm.showFilterHelpPanel">
  </header-section>
    <body-section transclude-to="body">
            <md-tabs    flex md-selected="vm.tabMetadata.selectedIndex"
                       md-align-tabs="top" layout-fill  md-dynamic-height>

                <md-tab   ng-repeat="tab in vm.tabs"
                        ng-disabled="tab.disabled"
                        md-on-select="vm.onTabSelected(tab)" flex
                        >
                    <md-tab-label> {{tab.title|fstatus}} </md-tab-label>
                    <md-tab-body>
                        <md-divider></md-divider>
                    <div ng-hide="vm.viewType != 'list'" ng-show="vm.viewType == 'list'">
                        <div ng-if="vm.showProgress" class="md-list-table-progress">
                        <md-progress-linear md-mode="indeterminate"></md-progress-linear>
                            <br/><br/>
                        </div>
                    <md-list flex layout-fill ng-show="vm.loading == false" class="list-item-table">
                        <md-list-item  dir-paginate="job in tab.data.content|itemsPerPage:vm.paginationData.rowsPerPage" pagination-id="vm.paginationId(tab)" total-items="tab.data.total" current-page="tab.currentPage" >
                            <div layout="row" layout-fill>
                                <div flex="30" layout="column" style="overflow:hidden; text-overflow:ellipsis;"  class="item-column  md-list-item-text" ng-click="vm.jobDetails($event,job)">
                                   <span class="item-title">
                                       {{job.jobName}}
                                   </span>
                                   <span  ng-class="{'success':(job.displayStatus == 'COMPLETED' || job.displayStatus =='STARTING' || job.displayStatus =='STARTED' ),'error':job.displayStatus == 'FAILED', 'warn':(job.displayStatus == 'STOPPING' || job.displayStatus =='STOPPED'), 'abandoned':job.displayStatus == 'ABANDONED','unknown':job.displayStatus == 'UNKNOWN'}" class="column-title-bottom">
                                       <ng-md-icon icon="{{job.icon}}" size="20" options='{"rotation": "clock"}' ></ng-md-icon>
                                       {{job.displayStatus}}</span>
                                </div>
                                <div flex="25" layout="column" hide show-gt-xs  show-lg show-xl show-sm show-md class="item-column  md-list-item-text" ng-click="vm.jobDetails($event,job)">
                                    <span class="item-title" ng-if="job.startTime">{{job.startTime | date: 'yyyy-MM-dd hh:mm:ss'}}</span>
                                    <span class="item-title" ng-if="job.startTime == undefined"> N/A </span>
                                    <span class="column-title column-title-bottom">Start Time</span>
                                </div>
                                <div flex="25" layout="column" hide show-gt-md class="item-column  md-list-item-text" ng-click="vm.jobDetails($event,job)">
                                    <span class="item-title">{{job.runTime | time }}</span>
                                    <span class="column-title column-title-bottom">Run Time</span>
                                </div>
                                <div flex="20" flex-gt-md="20" layout="row" hide show-gt-sm class="item-column  md-list-item-text" ng-if="!job.stream">
                                    <md-button class="border-btn action-btn" ng-if="job.status !='COMPLETED' && job.status !='FAILED' && job.status !='ABANDONED' && vm.allowAdmin" ng-click="vm.failJob($event,job)">失败
                                    </md-button>
                                    <md-button class="border-btn action-btn" ng-if="job.status =='FAILED' && vm.allowAdmin" ng-click="vm.abandonJob($event,job)">放弃</md-button>
                                    <span ng-if="job.errorMessage != ''">
                                        <br/>
                                        <span class="md-warn md-caption">{{job.errorMessage}}</span>
                                    </span>
                                </div>
                            </div>
                            <md-divider ng-if="!$last"></md-divider>

                        </md-list-item>
                        <md-item  ng-show="vm.showProgress == false && tab.data.content.length ==0" style="padding:10px">
                            未找到结果
                        </md-item >
                        <md-divider></md-divider>
                        <md-list-item   layout-align="end center"  layout-row class="pagination-list-item">
                            <dir-pagination-controls pagination-id="vm.paginationId(tab)" ng-if="vm.viewType == 'list'"
                                                     auto-hide="false"
                                                     max-size="5"
                                                     direction-links="true"
                                                     boundary-links="false"
                                                     template-url="js/common/dir-pagination/dirPagination.tpl.html"
                                                     on-page-change="vm.onPaginationChange(newPageNumber)"
                                                     label="Rows per page"
                                                     rows-per-page="vm.paginationData.rowsPerPage"
                                                     rows-per-page-options="vm.paginationData.rowsPerPageOptions"
                                                     class="pagination-row">
                            </dir-pagination-controls>
                        </md-list-item>


                    </md-list>
                    </div>
                    <div ng-hide="vm.viewType != 'table'" ng-show="vm.viewType == 'table'">

                        <md-table-container>
                            <table md-table md-progress="vm.deferred.promise">
                                <thead md-head md-order="vm.paginationData.sort" md-on-reorder="vm.onOrderChange" >
                                <tr md-row>
                                    <th md-column name="Job Name" md-order-by="jobName">作业名称</th>
                                    <th md-column  name="State">状况</th>
                                    <th md-column  name="Feed" md-order-by="feedName" ng-if="vm.hideFeedColumn == false">管道</th>
                                    <th md-column  name="Start Time" md-order-by="startTime"   hide show-gt-sm >开始时间</th>
                                    <th md-column  name="Run Time" md-order-by="runTime"  hide show-gt-md>运行时间 </th>
                                    <th md-column  name="Status" md-order-by="status">状态</th>
                                    <th md-column  name="Action" md-hide show-gt-md >动作</th>
                                </tr>
                                </thead>
                                <tbody md-body>
                                <tr md-row ng-repeat="job in tab.data.content" ng-click="vm.jobDetails($event,job)">
                                    <td md-cell>{{job.jobName}}</td>
                                    <td md-cell>
                               <span  ng-class="{'success':(job.displayStatus == 'COMPLETED' || job.displayStatus =='STARTING' || job.displayStatus =='STARTED' ),'error':job.displayStatus == 'FAILED', 'warn':(job.displayStatus == 'STOPPING' || job.displayStatus =='STOPPED'), 'abandoned':job.displayStatus == 'ABANDONED','unknown':job.displayStatus == 'UNKNOWN'}">
                                       <ng-md-icon icon="{{job.icon}}" size="20" >
                                       </ng-md-icon>
                                       <span hide show-gt-md>{{job.displayStatus|fstatus}}</span></span>

                                    </td>
                                    <td md-cell ng-if="vm.hideFeedColumn == false">{{job.feedName}}</td>
                                    <td md-cell hide show-gt-sm>{{job.startTime | date:'yyyy-MM-dd hh:mm:ss'}}</td>
                                    <td md-cell hide show-gt-md>{{job.runTime | time}}</td>
                                    <td md-cell >{{job.status|fstatus}}</td>
                                    <td md-cell hide show-gt-md>
                                        <md-button class="border-btn action-btn" ng-if="job.status !='COMPLETED' && job.status !='FAILED' && vm.allowAdmin" ng-click="vm.failJob($event,job)">失败</md-button>
                                        <md-button class="border-btn action-btn" ng-if="job.status =='FAILED' && vm.allowAdmin" ng-click="vm.abandonJob($event,job)">放弃</md-button>
                                         <span ng-if="job.errorMessage != ''">
                                        <br/>
                                        <span class="md-warn md-caption">{{job.errorMessage}}</span>
                                    </span>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </md-table-container>

                        <md-table-pagination md-limit="vm.paginationData.rowsPerPage" md-page="tab.currentPage" md-total="{{tab.data.total}}" md-on-paginate="vm.onPaginationChange" md-limit-options="[5,10,20,50,100]"></md-table-pagination>

                    </div>
                        </md-tab-body>
                </md-tab>
            </md-tabs>
            </body-section>
            </card-layout>
